package main

import "fmt"

func main() {

	sum := 1
	fmt.Println("for")

	for i := 0; i <= 10; i++ {
		sum += i
	}
	fmt.Println(sum)

	// 这样写也可以，更像 While 语句形式
	fmt.Println("类型while")
	for sum <= 10 {
		sum += sum
	}
	fmt.Println(sum)

	fmt.Println("For-each range 循环")

	strings := []string{"google", "good"}

	for i, s := range strings {
		fmt.Println(i, s)
	}

	numbers := [6]int{1, 2, 3, 4}
	for i, x := range numbers {
		fmt.Printf("第 %d 位 x 的值 = %d\n", i, x)

	}

	fmt.Println("for 循环的 range 格式可以省略 key 和 value，如下实例：")

	map1 := make(map[int]float32)

	map1[1] = 1.0
	map1[2] = 2.0
	map1[3] = 3.0
	map1[4] = 4.0

	for key, value := range map1 {
		fmt.Printf("key is: %d - value is: %f\n", key, value)
	}

	for key := range map1 {
		fmt.Printf("key is: %d\n", key)
	}

	for _, value := range map1 {
		fmt.Printf("value is: %f\n", value)
	}
}
